<template>
  <div class="welcome-container">
    <el-container>
      <el-header>
        <div>
          <img src="../assets/heima.png" />
          <span>电商后台管理系统</span>
        </div>
        <el-button type="info" size="mini" @click="logout">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside :width="width">
          <div class="shou" @click="arrow()">|||</div>
          <!-- 导航菜单 -->
          <el-menu
            :default-active="defaultActive"
            :unique-opened="true"
            class="el-menu-vertical-demo"
            :collapse="flag"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#3aabf7"
            :router="true"
            :collapse-transition="false"
          >
            <el-submenu v-for="(item1,index) in list" :key="index" :index="item1.path">
              <template slot="title" class="Div">
                <i style="margin-right:5px" :class="iconsObj[item1.id]"></i>
                <span slot="title">{{item1.authName}}</span>
              </template>
              <el-menu-item-group v-for="(item2,index1) in item1.children" :key="index1">
                <el-menu-item @click="handleColor(item2.path)" :index="item2.path"><i class="el-icon-menu"></i>{{item2.authName}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 主体区域 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { Request_api } from "../api/index";
export default {
  data() {
    return {
      defaultActive:window.sessionStorage.getItem("defaultActive") || 'users',
      width: "200px",
      isCollapse: true,
      list: [],
      flag: false,
      iconsObj: {
        "125": "iconfont icon-user",
        "103": "iconfont icon-tijikongjian",
        "101": "iconfont icon-shangpin",
        "102": "iconfont icon-danju",
        "145": "iconfont icon-baobiao",
      },
    };
  },
  methods: {
    logout() {
      window.sessionStorage.removeItem("token");
      this.$router.push("/login");
    },
    handleColor(key) {
      this.defaultActive=key
      window.sessionStorage.setItem('defaultActive',key)
    },
    async Request() {
      const memulist = await Request_api();
      var { data: res } = memulist;
      this.list = res.data;
    },
    arrow() {
      this.flag = !this.flag;
      this.width = this.width == "64px" ? "200px" : "64px";
    },
  },
  created() {
    this.Request();
  },
};
</script>
<style scoped lang='less'>
.welcome-container {
  height: 100%;
  > .el-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    .el-header {
      background-color: #373d41;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      > div {
        display: flex;
        align-items: center;
        color: rgb(255, 255, 255);
        font-size: 20px;
        span {
          margin-left: 10px;
        }
      }
      .el-button {
        height: 40px;
      }
    }
    section {
      flex: 1;
      .el-aside {
        background-color: #333744;
        .shou {
          display: flex;
          justify-content: center;
          color: rgb(255, 255, 255);
          font-weight: 700;
        }
        .el-menu {
          border: 0;
        }
      }
      .el-main {
        background-color: #eaedf1;
      }
    }
  }
}
</style>